package com.xoms.front.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.front.model.OrderBean;
import com.xoms.front.persist.dao.OrderDao;

@Repository
public class OrderImpl extends BaseImpl implements OrderDao {

	final String NAME_SPACE = NAME_SPACE_HEADER + ".OrderMapper";

	@Override
	public int insert(OrderBean bean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", bean);
	}

	@Override
	public int selectCount() {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount");
	}

	@Override
	public List<OrderBean> selectList(int page, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);
	}

	@Override
	public OrderBean selectByOrderNo(String orderNo) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orderNo", orderNo);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectByOrderNo", params);
	}

	@Override
	public int updateStatusByOid(String oid, String tradeNo, int status, String payCallRes) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("oid", oid);
		params.put("status", status);
		params.put("tradeNo", tradeNo);
		params.put("payCallRes", payCallRes);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateStatusByOid", params);
	}

}
